package com.zhou.framework.config;

import com.zhou.framework.jwt.interceptor.AuthenticationInterceptor;
import com.zhou.org.interceptor.RightInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lang.zhou
 * @date 2022/4/29 16:46
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] exclude = new String[]{"/images/**","**/*.js",
                "/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**", "/doc.html/**"
                ,"/fonts/**","**/*.html","/error/400","/error/401","/error/404","/error/500"};
        registry.addInterceptor(authenticationInterceptor()).addPathPatterns("/**").excludePathPatterns(exclude);
        registry.addInterceptor(rightInterceptor()).addPathPatterns("/**").excludePathPatterns(exclude);
    }
    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        AuthenticationInterceptor interceptor = new AuthenticationInterceptor();
        return interceptor;
    }
    @Bean
    public RightInterceptor rightInterceptor() {
        RightInterceptor interceptor = new RightInterceptor();
        return interceptor;
    }
}
